﻿@using System.Data;
@using GatewayServer.Common;

@{
    ViewBag.PageTitle = "洪峰智能";

    Layout = "~/Views/Shared/PageTemplate.cshtml";
}

<script>
    $(document).ready(function () {
        //  $("#sel_SearchType option[value='@(ViewBag.Type)']").attr("selected", true);

        if ("@(ViewBag.order)" == "upd") {
            getEdit("@(ViewBag.tp_guid)");
        }
        getConditionList_main();

    });
    function getEdit(dguid) {
        $.post("getPlain", { "flag": Math.random(), guid: dguid }, function (result) {
            var myobj = (result.data);
            $("#tp_title").val(myobj.tp_title);

            for (var i = 0; i < document.getElementById("tp_status").options.length; i++) {
                if (document.getElementById("tp_status").options[i].value == myobj.tp_status) {
                    document.getElementById("tp_status").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("tp_status").options[i].selected = false;

                }
            }

        });
    }




    function getConditionList_main() {
        $.post("getPlainItemList", { "flag": Math.random(), guid: $("#tp_guid").val(), type: "main" }, function (result) {
            var pagedata = (result.data);
            rowcount = 0;
            var htmlstr = "";
            document.getElementById("pagelist_main").innerHTML = "";


            htmlstr = htmlstr + "<tr class='plainItemTRTitle'>";
            htmlstr = htmlstr + "<td >序号</td >";
            htmlstr = htmlstr + "<td >标题</td >";
            htmlstr = htmlstr + "<td >状态</td >";
            htmlstr = htmlstr + "<td >类型</td >";
            htmlstr = htmlstr + "<td >指令</td >";
            htmlstr = htmlstr + "<td >条件</td >";
            htmlstr = htmlstr + "<td >值</td >";

            htmlstr = htmlstr + "<td >排序</td >";
            htmlstr = htmlstr + "<td >操作</td >";
            htmlstr = htmlstr + "</tr >";

            if (pagedata != null && pagedata.length > 0) {
                for (var i = 0; i < pagedata.length; i++) {
                    rowcount = i + 1;
                    htmlstr = htmlstr + "<tr>";

                    var status = "启用";
                    if (pagedata[i].tpi_status == 1) {
                        status = "禁用";
                    }
                    var type = "";
                    if (pagedata[i].tpi_type == 0) {
                        type = "运行设备指令";
                    }
                    else if (pagedata[i].tpi_type == 100) {
                        type = "延时等待";
                    }
                    else if (pagedata[i].tpi_type == 2) {
                        type = "等待条件成立";
                    }
                    else if (pagedata[i].tpi_type == 1) {
                        type = "运行条件触发器";
                    }
                    htmlstr = htmlstr + "<td >" + rowcount + "</td >";
                    htmlstr = htmlstr + "<td >" + pagedata[i].tpi_title + "</td >";
                    htmlstr = htmlstr + "<td >" + status + "</td >";
                    htmlstr = htmlstr + "<td >" + type + "</td >";
                    htmlstr = htmlstr + "<td >" + pagedata[i].tpi_key + "</td >";
                    htmlstr = htmlstr + "<td >" + pagedata[i].tpi_value_rlue + "</td >";
                    htmlstr = htmlstr + "<td >" + pagedata[i].tpi_value + "</td >";

                    htmlstr = htmlstr + "<td >" + pagedata[i].tpi_order + "</td >";
                    htmlstr = htmlstr + "<td ><a href=\"javascript:delItem('" + pagedata[i].tpi_guid + "')\">删除</a> </td >";
                    htmlstr = htmlstr + "</tr >";

                }
                document.getElementById("pagelist_main").innerHTML = htmlstr;
            }
        });
    }



</script>

<style>
    #pagelist_follow {
        width: 100%;
    }

    #pagelist_main {
        width: 100%;
    }

    .kv-item label {
        width: 100px;
    }

    .plainItemTable {
    }

        .plainItemTable td {
            line-height: 30px;
        }

    .plainItemTRTitle td {
        font-weight: bold;
        background-color: aliceblue;
    }
</style>
<div id="saper-container">
    <form id="addForm" name="addForm" action="list" method="post">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>流程设计</h2>
            </div>
            <div class="subfiled-content">

                <div id="" title="添加/编辑">
                    <form action="" name="addForm" id="addForm" method="post">

                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>场景标题：</label>
                            <div class="kv-item-content">
                                <input type="text" name="tp_title" id="tp_title" placeholder="场景标题" />
                                <input type="hidden" name="tp_guid" id="tp_guid" value="@ViewBag.tp_guid" />
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>状态：</label>
                            <div class="kv-item-content">
                                <select id="tp_status" name="tp_status" style="width:130px;">
                                    <option value="0">启用</option>
                                    <option value="1">禁用</option>
                                </select>

                            </div>
                        </div>


                        <div style="background-color:antiquewhite;line-height:25px;padding:5px;font-weight: bold;">流程内容</div>

                        <div style="width:100%;">
                          

                            <div>
                                <table id="pagelist_main" class="plainItemTable"></table>
                            </div>

                        </div>


                        <div><hr /></div>
                        <div style="margin:0 auto;width:150px;">

                           
                            &nbsp;&nbsp; <input type="button" id="but_back1" name="but_back1" value="返回" onclick="window.location.href='list'" />
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div id="saper-ft"></div>
    </form>
</div>

